/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * book.java
 *
 * Created on 24-11-2011, 09:58:40
 */
package view;

import java.awt.BorderLayout;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Chien Thang
 */
public class Goods extends javax.swing.JInternalFrame {
//    private ArrayList<DepartmentDTO> listDepartment = null;

    /**
     * Creates new form book
     */
    public Goods() {
        //sun.awt.SunToolkit.checkAndSetPolicy(this, true);
        setRootPane(createRootPane());
        setLayout(new BorderLayout());
        this.closable = true;
        this.maximizable = true;
        this.resizable = true;
        this.iconable = true;
//        isIcon = false;
//        setRootPaneCheckingEnabled(true);
//        desktopIcon = new JDesktopIcon(this);
//        updateUI();
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabEmpDepart = new javax.swing.JTabbedPane();
        pnEmpMgmt = new javax.swing.JPanel();
        lbEmpID = new javax.swing.JLabel();
        txtEmpID = new javax.swing.JTextField();
        lbName = new javax.swing.JLabel();
        txtEmpName = new javax.swing.JTextField();
        lbAddress = new javax.swing.JLabel();
        txtAddress = new javax.swing.JTextField();
        lbPhoneNumber = new javax.swing.JLabel();
        txtPhoneNumber = new javax.swing.JTextField();
        lbDepartment = new javax.swing.JLabel();
        cbbDepartment = new javax.swing.JComboBox();
        btAddEmp = new javax.swing.JButton();
        btResetEmp = new javax.swing.JButton();
        txtSearch = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableEmp = new javax.swing.JTable();
        btDeleteEmp = new javax.swing.JButton();
        btUpdateEmp = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        btExitEmp = new javax.swing.JButton();
        pnDepartMgmt = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tableDepart = new javax.swing.JTable();
        jLabel9 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        btAddDepart = new javax.swing.JButton();
        btUpdateDepart = new javax.swing.JButton();
        btResetDepart = new javax.swing.JButton();
        btExitDepart = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        lbDepartID = new javax.swing.JLabel();
        lbDepartName = new javax.swing.JLabel();
        txtDepartName = new javax.swing.JTextField();
        txtDepartID = new javax.swing.JTextField();

        setTitle("Employee and Department Management");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/image/iconFormEmp.png"))); // NOI18N
        setMinimumSize(new java.awt.Dimension(800, 600));
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosed(evt);
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        tabEmpDepart.setTabPlacement(javax.swing.JTabbedPane.LEFT);
        tabEmpDepart.setMaximumSize(new java.awt.Dimension(1280, 1024));
        tabEmpDepart.setMinimumSize(new java.awt.Dimension(800, 600));
        tabEmpDepart.setPreferredSize(new java.awt.Dimension(800, 600));

        pnEmpMgmt.setBackground(new java.awt.Color(15, 125, 178));
        pnEmpMgmt.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED, new java.awt.Color(255, 255, 255), new java.awt.Color(255, 0, 0)), "EMPLOYEE MANAGEMENT", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(255, 255, 255))); // NOI18N
        pnEmpMgmt.setPreferredSize(new java.awt.Dimension(1280, 1024));

        lbEmpID.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        lbEmpID.setForeground(new java.awt.Color(255, 255, 255));
        lbEmpID.setText("Employee ID");

        txtEmpID.setEditable(false);

        lbName.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        lbName.setForeground(new java.awt.Color(255, 255, 255));
        lbName.setText("Name");

        lbAddress.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        lbAddress.setForeground(new java.awt.Color(255, 255, 255));
        lbAddress.setText("Address");

        lbPhoneNumber.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        lbPhoneNumber.setForeground(new java.awt.Color(255, 255, 255));
        lbPhoneNumber.setText("Phone number");

        lbDepartment.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        lbDepartment.setForeground(new java.awt.Color(255, 255, 255));
        lbDepartment.setText("Department");

        btAddEmp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/Add.png"))); // NOI18N
        btAddEmp.setText("Add");
        btAddEmp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddEmpActionPerformed(evt);
            }
        });

        btResetEmp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/Reset.png"))); // NOI18N
        btResetEmp.setText("Reset");
        btResetEmp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btResetEmpActionPerformed(evt);
            }
        });

        txtSearch.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                txtSearchCaretUpdate(evt);
            }
        });

        tableEmp.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Employee ID", "Name", "Address", "Phone number", "Department"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tableEmp.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tableEmp.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tableEmpMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tableEmp);

        btDeleteEmp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/Delete.png"))); // NOI18N
        btDeleteEmp.setText("Delete");
        btDeleteEmp.setEnabled(false);
        btDeleteEmp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDeleteEmpActionPerformed(evt);
            }
        });

        btUpdateEmp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/Edit.png"))); // NOI18N
        btUpdateEmp.setText("Update");
        btUpdateEmp.setEnabled(false);
        btUpdateEmp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btUpdateEmpActionPerformed(evt);
            }
        });

        jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/Emloyee.png"))); // NOI18N

        btExitEmp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/Exit.png"))); // NOI18N
        btExitEmp.setText("Exit");
        btExitEmp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExitEmpActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnEmpMgmtLayout = new javax.swing.GroupLayout(pnEmpMgmt);
        pnEmpMgmt.setLayout(pnEmpMgmtLayout);
        pnEmpMgmtLayout.setHorizontalGroup(
            pnEmpMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnEmpMgmtLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnEmpMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnEmpMgmtLayout.createSequentialGroup()
                        .addComponent(jScrollPane1)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnEmpMgmtLayout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnEmpMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtSearch, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnEmpMgmtLayout.createSequentialGroup()
                                .addGroup(pnEmpMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbEmpID)
                                    .addComponent(lbPhoneNumber)
                                    .addComponent(lbDepartment)
                                    .addComponent(lbName)
                                    .addComponent(lbAddress)
                                    .addComponent(btAddEmp))
                                .addGap(10, 10, 10)
                                .addGroup(pnEmpMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtEmpName)
                                    .addGroup(pnEmpMgmtLayout.createSequentialGroup()
                                        .addComponent(btUpdateEmp)
                                        .addGap(10, 10, 10)
                                        .addComponent(btDeleteEmp)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(btResetEmp)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(btExitEmp))
                                    .addComponent(txtEmpID)
                                    .addComponent(txtAddress)
                                    .addComponent(txtPhoneNumber)
                                    .addComponent(cbbDepartment, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addGap(89, 89, 89))))
        );
        pnEmpMgmtLayout.setVerticalGroup(
            pnEmpMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnEmpMgmtLayout.createSequentialGroup()
                .addGroup(pnEmpMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnEmpMgmtLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(pnEmpMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbEmpID)
                            .addComponent(txtEmpID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnEmpMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtEmpName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbName))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnEmpMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbAddress))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnEmpMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtPhoneNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbPhoneNumber))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnEmpMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbbDepartment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbDepartment))
                        .addGap(18, 18, 18)
                        .addGroup(pnEmpMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btResetEmp)
                            .addComponent(btDeleteEmp)
                            .addComponent(btAddEmp)
                            .addComponent(btUpdateEmp)
                            .addComponent(btExitEmp)))
                    .addComponent(jLabel8))
                .addGap(18, 18, 18)
                .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE)
                .addContainerGap())
        );

        tabEmpDepart.addTab("Employee Management", new javax.swing.ImageIcon(getClass().getResource("/image/TextEdit.png")), pnEmpMgmt); // NOI18N

        pnDepartMgmt.setBackground(new java.awt.Color(15, 125, 178));
        pnDepartMgmt.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED, new java.awt.Color(255, 255, 255), new java.awt.Color(255, 0, 0)), "DEPARTMENT MANAGEMENT", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(255, 255, 255))); // NOI18N

        tableDepart.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Department name"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tableDepart.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tableDepartMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tableDepart);

        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/Publisher.png"))); // NOI18N

        jPanel2.setBackground(new java.awt.Color(15, 125, 178));

        btAddDepart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/Add.png"))); // NOI18N
        btAddDepart.setText("Add");
        btAddDepart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddDepartActionPerformed(evt);
            }
        });

        btUpdateDepart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/Edit.png"))); // NOI18N
        btUpdateDepart.setText("Update");
        btUpdateDepart.setEnabled(false);
        btUpdateDepart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btUpdateDepartActionPerformed(evt);
            }
        });

        btResetDepart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/Reset.png"))); // NOI18N
        btResetDepart.setText("Reset");
        btResetDepart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btResetDepartActionPerformed(evt);
            }
        });

        btExitDepart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/Exit.png"))); // NOI18N
        btExitDepart.setText("Exit");
        btExitDepart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExitDepartActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(btAddDepart, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btUpdateDepart)
                .addGap(18, 18, 18)
                .addComponent(btResetDepart)
                .addGap(18, 18, 18)
                .addComponent(btExitDepart, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btExitDepart)
                    .addComponent(btResetDepart)
                    .addComponent(btUpdateDepart)
                    .addComponent(btAddDepart))
                .addContainerGap(35, Short.MAX_VALUE))
        );

        jPanel3.setBackground(new java.awt.Color(15, 125, 178));

        lbDepartID.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        lbDepartID.setForeground(new java.awt.Color(255, 255, 255));
        lbDepartID.setText("Department ID");

        lbDepartName.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        lbDepartName.setForeground(new java.awt.Color(255, 255, 255));
        lbDepartName.setText("Department name");

        txtDepartID.setEditable(false);
        txtDepartID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDepartIDActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbDepartName)
                    .addComponent(lbDepartID))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtDepartName)
                    .addComponent(txtDepartID, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE))
                .addContainerGap(44, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbDepartID)
                    .addComponent(txtDepartID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbDepartName)
                    .addComponent(txtDepartName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout pnDepartMgmtLayout = new javax.swing.GroupLayout(pnDepartMgmt);
        pnDepartMgmt.setLayout(pnDepartMgmtLayout);
        pnDepartMgmtLayout.setHorizontalGroup(
            pnDepartMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnDepartMgmtLayout.createSequentialGroup()
                .addGroup(pnDepartMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnDepartMgmtLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel9)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnDepartMgmtLayout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 533, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnDepartMgmtLayout.createSequentialGroup()
                        .addContainerGap(76, Short.MAX_VALUE)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(100, 100, 100)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnDepartMgmtLayout.setVerticalGroup(
            pnDepartMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnDepartMgmtLayout.createSequentialGroup()
                .addGroup(pnDepartMgmtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addGroup(pnDepartMgmtLayout.createSequentialGroup()
                        .addGap(46, 46, 46)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
                .addContainerGap())
        );

        tabEmpDepart.addTab("Department Management", new javax.swing.ImageIcon(getClass().getResource("/image/publisher2.png")), pnDepartMgmt); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabEmpDepart, javax.swing.GroupLayout.DEFAULT_SIZE, 870, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(tabEmpDepart, javax.swing.GroupLayout.DEFAULT_SIZE, 649, Short.MAX_VALUE)
                .addContainerGap())
        );

        tabEmpDepart.getAccessibleContext().setAccessibleName("Add a new book");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btAddDepartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddDepartActionPerformed
        addNewDepartment();
        loadDepartment();
        loadDepartmentToTable();
        loadDepartmentToCbb();
    }//GEN-LAST:event_btAddDepartActionPerformed

    private void txtSearchCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_txtSearchCaretUpdate
        searchEmployee();
}//GEN-LAST:event_txtSearchCaretUpdate

    private void btResetEmpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btResetEmpActionPerformed
        txtEmpID.setText("");
        txtEmpName.setText("");
        txtAddress.setText("");
        txtPhoneNumber.setText("");
        cbbDepartment.setSelectedItem("");
        btAddEmp.setEnabled(true);
        btUpdateEmp.setEnabled(false);
        btDeleteEmp.setEnabled(false);
        searchEmployee();
}//GEN-LAST:event_btResetEmpActionPerformed

    private void btAddEmpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddEmpActionPerformed
        addNewEmployee();
        searchEmployee();
    }//GEN-LAST:event_btAddEmpActionPerformed

    private void tableEmpMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableEmpMouseClicked
        showEmployeeDetails();
        btAddEmp.setEnabled(false);
        btUpdateEmp.setEnabled(true);
        btDeleteEmp.setEnabled(true);
    }//GEN-LAST:event_tableEmpMouseClicked

    private void btUpdateEmpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btUpdateEmpActionPerformed
        updateEmployeeInformation();
        searchEmployee();
    }//GEN-LAST:event_btUpdateEmpActionPerformed

    private void btDeleteEmpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDeleteEmpActionPerformed
        deleteEmployeeInformation();
        searchEmployee();
        btDeleteEmp.setEnabled(false);
    }//GEN-LAST:event_btDeleteEmpActionPerformed

    private void btUpdateDepartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btUpdateDepartActionPerformed
        updateDepartmentInformation();
        loadDepartment();
        loadDepartmentToTable();
        loadDepartmentToCbb();
        searchEmployee();

    }//GEN-LAST:event_btUpdateDepartActionPerformed

    private void tableDepartMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableDepartMouseClicked
        showDepartmentInformation();
        btAddDepart.setEnabled(false);
        btUpdateDepart.setEnabled(true);
    }//GEN-LAST:event_tableDepartMouseClicked

    private void btResetDepartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btResetDepartActionPerformed
        txtDepartID.setText("");
        txtDepartName.setText("");
        btAddDepart.setEnabled(true);
        btUpdateDepart.setEnabled(false);
    }//GEN-LAST:event_btResetDepartActionPerformed

    private void formInternalFrameClosed(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosed
        MainForm.goodsForm = null;
    }//GEN-LAST:event_formInternalFrameClosed

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        // TODO add your handling code here:
        loadDepartment();
        loadDepartmentToCbb();
        loadDepartmentToTable();
        searchEmployee();
    }//GEN-LAST:event_formInternalFrameOpened

    private void btExitEmpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExitEmpActionPerformed
        this.dispose();
    }//GEN-LAST:event_btExitEmpActionPerformed

    private void btExitDepartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExitDepartActionPerformed
        this.dispose();
    }//GEN-LAST:event_btExitDepartActionPerformed

    private void txtDepartIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDepartIDActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDepartIDActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAddDepart;
    private javax.swing.JButton btAddEmp;
    private javax.swing.JButton btDeleteEmp;
    private javax.swing.JButton btExitDepart;
    private javax.swing.JButton btExitEmp;
    private javax.swing.JButton btResetDepart;
    private javax.swing.JButton btResetEmp;
    private javax.swing.JButton btUpdateDepart;
    private javax.swing.JButton btUpdateEmp;
    private javax.swing.JComboBox cbbDepartment;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lbAddress;
    private javax.swing.JLabel lbDepartID;
    private javax.swing.JLabel lbDepartName;
    private javax.swing.JLabel lbDepartment;
    private javax.swing.JLabel lbEmpID;
    private javax.swing.JLabel lbName;
    private javax.swing.JLabel lbPhoneNumber;
    private javax.swing.JPanel pnDepartMgmt;
    private javax.swing.JPanel pnEmpMgmt;
    private javax.swing.JTabbedPane tabEmpDepart;
    private javax.swing.JTable tableDepart;
    private javax.swing.JTable tableEmp;
    private javax.swing.JTextField txtAddress;
    private javax.swing.JTextField txtDepartID;
    private javax.swing.JTextField txtDepartName;
    private javax.swing.JTextField txtEmpID;
    private javax.swing.JTextField txtEmpName;
    private javax.swing.JTextField txtPhoneNumber;
    private javax.swing.JTextField txtSearch;
    // End of variables declaration//GEN-END:variables
    private DefaultTableModel modelEmployee;
    private DefaultTableModel modelDepartment;

    private void loadDepartmentToCbb() {
//        try {
//            DefaultComboBoxModel model = new DefaultComboBoxModel(listDepartment.toArray());
//            model.addElement("");
//            model.setSelectedItem("");
//            cbbDepartment.setModel(model);
//        }
//        catch (Exception ex) {
//            ex.printStackTrace();
//        }
    }

    private void addNewEmployee() {
//        if(checkEmpInformation()){
//            try {
//                control = EmployeeMgmtControl.newinit();
//                DepartmentDTO department = new DepartmentDTO();
//                department = (DepartmentDTO) cbbDepartment.getSelectedItem();
//                int rs = control.addNewEmployee(txtEmpName.getText().trim(), txtAddress.getText().trim(), txtPhoneNumber.getText().trim(), department.getId());
//                if(rs > 0)
//                    displaySucess("Add new employee successfully.");
//                else
//                    displayFailure("Add new employee unsuccessfully.");
//            }
//            catch (Exception ex) {
//                ex.printStackTrace();
//                displayFailure("Can not process data from database server. Please try to configure database server accurately.");
//            }
//        }
//        else
//            displayFailure("Employee information is not adequate.");
    }

    private boolean checkEmpInformation() {
        if (txtEmpName.getText().isEmpty() | txtAddress.getText().isEmpty() | txtPhoneNumber.getText().isEmpty()
                | (cbbDepartment.getSelectedIndex() == cbbDepartment.getItemCount() - 1)) {
            return false;
        } else {
            return true;
        }
    }

    private void searchEmployee() {
//        try {
//            control = EmployeeMgmtControl.newinit();
//            ArrayList<EmployeeDTO> list = control.searchEmployee(txtSearch.getText());
//            modelEmployee = (DefaultTableModel) tableEmp.getModel();
//            modelEmployee.setNumRows(0);
//            for(int i=0; i<list.size(); i++){
//                EmployeeDTO emp = new EmployeeDTO();
//                emp = list.get(i);
//                Vector vtEmp = new Vector();
//                vtEmp.add(emp.getId());
//                vtEmp.add(emp.getName());
//                vtEmp.add(emp.getAddress());
//                vtEmp.add(emp.getPhoneNumber());
//                vtEmp.add(emp.getDepartment());
//                modelEmployee.addRow(vtEmp);
//            }
//        }
//        catch (Exception ex) {
//            ex.printStackTrace();
//            displayFailure("Can not process data from database server. Please try to configure database server accurately.");
//        }
    }

    private void showEmployeeDetails() {
        int index = tableEmp.getSelectedRow();
        txtEmpID.setText(modelEmployee.getValueAt(index, 0).toString());
        txtEmpName.setText(modelEmployee.getValueAt(index, 1).toString());
        txtAddress.setText(modelEmployee.getValueAt(index, 2).toString());
        txtPhoneNumber.setText(modelEmployee.getValueAt(index, 3).toString());
        for (int i = 0; i < cbbDepartment.getItemCount(); i++) {
            if (modelEmployee.getValueAt(index, 4).toString().equals(cbbDepartment.getItemAt(i).toString())) {
                cbbDepartment.setSelectedIndex(i);
                break;
            }
        }
    }

    private void updateEmployeeInformation() {
//        if(checkEmpInformation()){
//            try {
//                control = EmployeeMgmtControl.newinit();
//                DepartmentDTO department = new DepartmentDTO();
//                department = (DepartmentDTO) cbbDepartment.getSelectedItem();
//                int rs = control.updateEmployeeInformation(Integer.valueOf(txtEmpID.getText()), txtEmpName.getText(), txtAddress.getText(), txtPhoneNumber.getText(), department.getId());
//                if (rs > 0) {
//                    displaySucess("Update employee information successfully.");
//                } else {
//                    displayFailure("Can not update employee information because this Employee ID does not exist.");
//                }
//            }
//            catch (Exception ex) {
//                ex.printStackTrace();
//                displayFailure("Can not load data from database server. Please try to configure database server accurately.");
//            }
//        }
//        else
//            displayFailure("Employee information is not adequate.");
    }

    private void deleteEmployeeInformation() {
//        int delete = JOptionPane.showConfirmDialog(null,"Are you sure?", "Question", 1, JOptionPane.YES_NO_CANCEL_OPTION, new javax.swing.ImageIcon("src\\image\\Question.png"));
//        if(delete==0){
//            try {
//                int[] arr = tableEmp.getSelectedRows();
//                ArrayList<Integer> list = new ArrayList<Integer>();
//                for (int i = 0; i < arr.length; i++) {
//                    list.add(Integer.valueOf(modelEmployee.getValueAt(arr[i], 0).toString()));
//                }
//                control = EmployeeMgmtControl.newinit();
//                ArrayList<Integer> result = new ArrayList<Integer>();
//                result = control.deleteEmployeeInformation(list);
//                String str = "";
//                int count = 0;
//                for(int i=0; i<result.size();i++){
//                    if(result.get(i) == 0){
//                        count++;
//                        if(count>1)
//                            str += ", " + list.get(i).toString();
//                        else
//                            str += list.get(i).toString();
//                    }
//                }
//                str = "("+str+")";
//                if(count == 0)
////                    displaySucess(list.size() + " employee information record(s) was deleted.");
//                    displaySucess("Delete employee information record successfully.");
//
//
//                else
////                  displayFailure((list.size()- count) + " employee information record(s) was deleted. Employee ID " + str + " can not bedeleted.");
//                    displayFailure("Delete employee information record unsuccessfully.");
//
//            }
//            catch (Exception ex) {
//                ex.printStackTrace();
//                displayFailure("Can not load data from database server. Please try to configure database server accurately.");
//            }
//        }
    }

    private void addNewDepartment() {
//        if(txtDepartName.getText().isEmpty())
//            displayFailure("Department information is not adequate.");
//        else{
//            try {
//                control = EmployeeMgmtControl.newinit();
//                int rs = control.addNewDepartment(txtDepartName.getText().trim());
//                if(rs > 0)
//                    displaySucess("Add new department successfully.");
//                else
//                    displayFailure("Add new department unsuccessfully.");
//            } catch (Exception ex) {
//                ex.printStackTrace();
//                displayFailure("Can not load data from database server. Please try to configure database server accurately.");
//            }
//        }
    }

    private void loadDepartmentToTable() {
//        try {
//            modelDepartment = (DefaultTableModel) tableDepart.getModel();
//            modelDepartment.setNumRows(0);
//            for(int i=0; i<listDepartment.size(); i++){
//                DepartmentDTO department = new DepartmentDTO();
//                department = listDepartment.get(i);
//                Vector vtDepartment = new Vector();
//                vtDepartment.add(department.getId());
//                vtDepartment.add(department.getName());
//                modelDepartment.addRow(vtDepartment);
//            }
//        }
//        catch (Exception ex) {
//            ex.printStackTrace();
//        }
    }

    private void updateDepartmentInformation() {
//        if(txtDepartID.getText().isEmpty() | txtDepartName.getText().isEmpty())
//            displayFailure("Department information is not adequate.");
//        
//        else{
//            try {
//                control = control.newinit();
//                int rs = control.updateDepartmentInformation(Integer.valueOf(txtDepartID.getText()), txtDepartName.getText());
//                if (rs > 0) {
//                    displaySucess("Update department information successfully.");
//                } else {
//                    displayFailure("Can not update employee department because this Department ID does not exist.");
//                }
//            }
//            catch (Exception ex) {
//                ex.printStackTrace();
//                displayFailure("Can not load data from database server. Please try to configure database server accurately.");
//            }
//        }
    }

    private void showDepartmentInformation() {
        int index = tableDepart.getSelectedRow();
        txtDepartID.setText(modelDepartment.getValueAt(index, 0).toString());
        txtDepartName.setText(modelDepartment.getValueAt(index, 1).toString());
    }

    private void loadDepartment() {
//        try {
//            control = EmployeeMgmtControl.newinit();
//            listDepartment = control.loadDepartment();
//        }
//        catch (Exception ex) {
//            ex.printStackTrace();
//            displayFailure("Can not load data from database server. Please try to configure database server accurately.");
//        }
    }
}
